<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>混入mixin</title>
    <script src="./../vue/vue.js"></script>
</head>
<body>

    <!-- 
        mixin 
            在组件内部进行递归 调用， 发生冲突时以组件数据优先 都会调用
        全局mixin
        
     -->
    <div id="app">
        <component-base></component-base>
    </div>

    <script>

        let myMixin = {
            created: function(){
                console.log("执行myMixin 的 created 方法")
            },
            methods: {
                hello: function(){
                    console.log("hello mixin")
                }
            },
        }

        let BaseComponent = Vue.extend({
            mixins: [myMixin],
            data: function(){
                return {
                    title: "title"
                }
            },
            template: `
            <div>{{ title }}</div>
            `
        })

        // 全局mixin

        Vue.mixin({
            beforeCreate() {
                console.log("每一个都会执行")
            },
        })

        // let comonent = new BaseComponent()
        
        let vm = new Vue({
            el: "#app",
            mixins: [myMixin],
            components: {
                "component-base": BaseComponent
            },
            data: {

            },
            beforeCreate() {
                console.log("Vue beforeCreate")
            },
        })


    </script>
    
</body>
</html>